package zj.it.bhne.huanxin.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.hyphenate.chat.EMClient;
import com.hyphenate.easeui.widget.EaseTitleBar;

import java.util.Objects;

import zj.it.bhne.huanxin.R;
import zj.it.bhne.huanxin.activity.MainActivity;

public class SetFragment extends Fragment implements View.OnClickListener {


    private Button set_back;
    private TextView set_name;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_set, container, false);
        initView(view);
        //透明状态栏
        Objects.requireNonNull(getActivity()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        View views = new View(getContext());
        ViewGroup.LayoutParams params = new ViewGroup
                .LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 60);
        views.setLayoutParams(params);
        views.setBackgroundColor(Color.rgb(18, 150, 219));

        ViewGroup decorView = (ViewGroup) Objects.requireNonNull(getActivity()).getWindow().getDecorView();
        decorView.addView(views);
        return view;
    }


    private void initView(View view) {
        EaseTitleBar title_bar = view.findViewById(R.id.title_bar);
        title_bar.setTitle("设置");
        set_back = view.findViewById(R.id.set_back);
        set_back.setOnClickListener(this);
        set_name = view.findViewById(R.id.set_name);
        set_name.setOnClickListener(this);
        SharedPreferences preferences = Objects.requireNonNull(getActivity()).getSharedPreferences("ss", Context.MODE_PRIVATE);
        String name = preferences.getString("name","");
        set_name.setText(name);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.set_back:
                EMClient.getInstance().logout(true);
                startActivity(new Intent(getContext(), MainActivity.class));
                break;
        }
    }
}
